package com.chinafree.common.utils;

import javax.servlet.ServletContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

 public class ApplicationContextUtils {
    private static Logger logger = LoggerFactory.getLogger(ApplicationContextUtils.class);
    private static ApplicationContext cxt;
    private static ServletContext sxt;
 
    public static Object getBeanByName(String BeanName){
        logger.info(BeanName);
        if(StringUtils.isEmpty(BeanName))
            return null;
 
        logger.debug("在ApplicationContext中取名称为：\""+BeanName+"\"的Bean实例...");
  
        return cxt.getBean(BeanName);
    }
 
    public static ApplicationContext getCxt() {
        return cxt;
    }
    public static void setCxt(ApplicationContext cxt) {
        ApplicationContextUtils.cxt = cxt;
    }
    public static ServletContext getSxt() {
        return sxt;
    }
    public static void setSxt(ServletContext sxt) {
        ApplicationContextUtils.sxt = sxt;
    }
}
